//secondaryFuncBar这只是一个容纳二级菜单的div，里面没有任何的内容
//真正的内容是在点击sfunbar上的一级菜单项的时候，添加进去的。
var secondaryFuncBarHTML ='<div id="secondaryfuncbar">'+
											'</div>';

//应急值守的二级菜单
var YJZSSecondaryFuncBarHTML ='<div id="oneFXBB" class="forSecondaryFuncBar">分析报表</div>'+
	'<div id="oneYJTX" class="forSecondaryFuncBar">应急通讯</div>'+
	'<div id="oneXTZH" class="forSecondaryFuncBar">协调指挥</div>'+													
	'<div id="oneFZJC" class="forSecondaryFuncBar">辅助决策</div>'+													
	'<div id="oneYAPP" class="forSecondaryFuncBar">预案匹配</div>'+																									
	'<div id="oneXXBS" class="forSecondaryFuncBar">信息报送</div>'+													
	'<div id="oneYJZB" class="forSecondaryFuncBar">应急值班</div>';											
														

//事件管理的二级菜单
var SJGLSecondaryFuncBarHTML ='<div id="twoYJJCSJ" class="forSecondaryFuncBar">应急监测事件</div>'+
												    '<div id="twoQXYJSJ" class="forSecondaryFuncBar">气象预警事件</div>'+
													'<div id="twoALGLSJ" class="forSecondaryFuncBar">案例关联事件</div>'+
													'<div id="twoSJTJXX" class="forSecondaryFuncBar">事件统计信息</div>'+
													'<div id="twoCLGCSJ" class="forSecondaryFuncBar">处理过程事件</div>'+
													'<div id="twoXXXBSJ" class="forSecondaryFuncBar">信息续报事件</div>'+
													'<div id="twoSJCX" class="forSecondaryFuncBar">事件查询</div>';

//应急调查的二级菜单
var YJDCSecondaryFuncBarHTML = '<div id="threeSBGL" class="forSecondaryFuncBar">设备管理</div>'+
														'<div id="threeXXCJ" class="forSecondaryFuncBar">数据管理</div>'+
														'<div id="threeDCWD" class="forSecondaryFuncBar">调查信息</div>'+
														//'<div id="threeXXCX" class="forSecondaryFuncBar">信息查询</div>'+
														//'<div id="threeXXDR" class="forSecondaryFuncBar">信息导入</div>'+
														'<div id="threeBBSC" class="forSecondaryFuncBar">报表输出</div>';

//应急监测的二级菜单
var YJJCSecondaryFuncBarHTML ='<div id="fourSBGL" class="forSecondaryFuncBar">设备管理</div>'+
														'<div id="fourCDSZ" class="forSecondaryFuncBar">测点设置</div>'+
														'<div id="fourZYJC" class="forSecondaryFuncBar">专业监测</div>'+
														'<div id="fourQCQF" class="forSecondaryFuncBar">群测群防</div>'+
														'<div id="fourCDWH" class="forSecondaryFuncBar">测点维护</div>';

//应急处置的二级菜单
var YJCZSecondaryFuncBarHTML ='<div id="fiveCZFA" class="forSecondaryFuncBar_long">处置方案管理</div>'+
														'<div id="fiveCZZL" class="forSecondaryFuncBar_long">处置资料管理</div>'+
														'<div id="fiveCZGC" class="forSecondaryFuncBar_long">处置过程管理</div>'+
														'<div id="fiveCZZY" class="forSecondaryFuncBar_long">处置资源管理</div>'+
														'<div id="fiveCZHX" class="forSecondaryFuncBar_long">处置后续管理</div>';

//基础信息的二级菜单
var JiChuXXSecondaryFuncBarHTML ='<div id="sixJCDC" class="forSecondaryFuncBar">基础调查</div>'+
															'<div id="sixYJAL" class="forSecondaryFuncBar">应急案例</div>'+
															'<div id="sixYJZS" class="forSecondaryFuncBar">应急知识</div>'+
															'<div id="sixYJYA" class="forSecondaryFuncBar">应急预案</div>'+
															'<div id="sixZDZH" class="forSecondaryFuncBar">重大灾害</div>'+
															'<div id="sixYJDC" class="forSecondaryFuncBar">应急调查</div>';

//应急会商的二级菜单
var YJHSSecondaryFuncBarHTML = '<div id="sevYJHS" class="forSecondaryFuncBar">应急会商</div>'+
															'<div id="sevHSGZLCGL" class="forSecondaryFuncBar_long">会商流程管理</div>'+
															'<div id="sevHSZYGL" class="forSecondaryFuncBar_long">会商资源管理</div>'+
															'<div id="sevHSSBGL" class="forSecondaryFuncBar_long">会商设备管理</div>'+
															'<div id="sevHSGCGL" class="forSecondaryFuncBar_long">会商过程管理</div>'+
															'<div id="sevHSSPGL" class="forSecondaryFuncBar_long">会商视频管理</div>'+
															'<div id="sevHSJLGL" class="forSecondaryFuncBar_long">会商结论管理</div>'+
															'<div id="sevYJHS" class="forSecondaryFuncBar">应急会商</div>';
//防控论证的二级菜单
var FKLZSecondaryFuncBarHTML =  '<div id="sevFKLZ" class="forSecondaryFuncBar">防控论证</div>'+
															'<div id="sevPGJLXXGL" class="forSecondaryFuncBar_long">评估结论管理</div>'+
															'<div id="sevQSYCJLGL" class="forSecondaryFuncBar_long">趋势预测管理</div>'+
															'<div id="sevLZSDFAGL" class="forSecondaryFuncBar_long">论证方案管理</div>'+
															'<div id="sevLZJLGL" class="forSecondaryFuncBar_long">论证结论管理</div>';
								
//决策信息的二级菜单
var JueCeXXSecondaryFuncBarHTML = '';

function loadSecondaryFuncBar(){
	$("body").append(secondaryFuncBarHTML);
	//默认加载“应急值守”的二级菜单
	addContentToSecondaryfuncbar("MMenu_1");
	//注册secondaryFuncBarDiv的点击事件
	$("#secondaryFuncBarDiv").click(showAndHideSecondaryFuncBar);
	//注册各个子模块的点击事件,出对话框
	$(".forSecondaryFuncBar").click(showFuncDlgById);
}

function getCurrentUserAuthoirty(MMID){
	//MMID：主菜单id
	var ids = MMID.split("_");
	var id = ids[1];
	var data;
	$.ajax({
		async:false,
		url:"authority_query.shtml",
		data:'mmid='+id,
		processData:false,
		dataType:"json",
		success:function(d,e){
			//debugger
			 data=d;
		},
		error:function(e,s){
			alert(e.toString());
		}
	});
	//debugger
	return data;
}

function processSecondaryBar(data){
  var currentSubMenuSet = $("#secondaryfuncbar > div");
  var list = data.data;
  currentSubMenuSet.each(function(i,item){
	  var subMenuName=item.innerHTML;
	  var subMenuAuthority;
	  var hasAuthority = false;
	  
	  $.each(list,function(j,listItem){
		  
		  if(listItem.functionName==subMenuName){
			  // 当前用户具有访问权限
			  hasAuthority = true;
			  subMenuAuthority = listItem;
		  }
	  })
	  if(!hasAuthority){
		  $(item).css("display","none");
	  }
	  else{
		  //debugger
		  var authorityString=subMenuAuthority.c+"_"+subMenuAuthority.u+"_"+subMenuAuthority.r+"_"+subMenuAuthority.d;
		  $.data(item,'authority',authorityString);
		  var test=$.data($("#oneYJZB")[0],'authority');
	  }
  });
}

function addContentToSecondaryfuncbar(divID){
	$("#secondaryFuncBarDiv").attr("class","secondaryFuncBarHide");
	$("#secondaryfuncbar").html("");
	switch(divID){
		case "MMenu_1":
			// 应急值守
			$("#secondaryfuncbar").css("width","560px");
			$("#secondaryfuncbar").append(YJZSSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "MMenu_10":
			// 事件管理
			$("#secondaryfuncbar").css("width","560px");
			$("#secondaryfuncbar").append(SJGLSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "MMenu_18":
			// 应急调查
			$("#secondaryfuncbar").css("width","480px");
			$("#secondaryfuncbar").append(YJDCSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "MMenu_26":
			// 应急监测
			$("#secondaryfuncbar").css("width","400px");
			$("#secondaryfuncbar").append(YJJCSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "MMenu_49":
			//应急处置
			$("#secondaryfuncbar").css("width","700px");
			$("#secondaryfuncbar").append(YJCZSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "JiChuXX":
			
			$("#secondaryfuncbar").css("width","480px");
			$("#secondaryfuncbar").append(JiChuXXSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "MMenu_35":
			// 应急会商
			$("#secondaryfuncbar").css("width","750px").append(YJHSSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			
			break;
		case "MMenu_42":
			// 防控论证
			$("#secondaryfuncbar").css("width","600px").append(FKLZSecondaryFuncBarHTML);
			$(".forSecondaryFuncBar").click(showFuncDlgById);
			break;
		case "JueCeXX":
			break;
	}
	var data=getCurrentUserAuthoirty(divID);
	processSecondaryBar(data);
	$("#secondaryFuncBarDiv").attr("class","secondaryFuncBarShow");
	$("#secondaryfuncbar").show('slide', { direction: 'right' }, 300, null);
}


//点击secondaryFuncBarDiv之后，隐藏或者展开secondaryfuncbar
function showAndHideSecondaryFuncBar(){
	if($("#secondaryFuncBarDiv").attr("class")=="secondaryFuncBarShow"){//如果是展开的
		$("#secondaryFuncBarDiv").attr("class","secondaryFuncBarHide");
		$("#secondaryfuncbar").hide('slide', { direction: 'right' }, 300, null);
	}else{
		$("#secondaryFuncBarDiv").attr("class","secondaryFuncBarShow");
		$("#secondaryfuncbar").show('slide', { direction: 'right' }, 300, null);
	}
}


//出功能对话框，通过id去获得，swtich——case
function showFuncDlgById(evt){
	var divID = evt.srcElement.id;
	switch(divID){
		case "oneYJTX":
			oneyjtxDlgInit();
			break;
		case "oneYJZB":
			oneyjzbDlgInit();
			break;
		case "oneXXBS":
			onexxbsDlgInit();
			break;
		case "oneXTZH":
			onextzhDlgInit();
			break;
		case "oneFZJC":
			onefzjcDlgInit();
			break;
		case "oneYAPP":
			oneyappDlgInit();
			break;
		case "oneFXBB":
			onefxbbDlgInit();
			break;
		case "twoYJJCSJ":
			break;
		case "twoQXYJSJ":
			break;
		case "twoALGLSJ":
			break;
		case "twoSJTJXX":
			break;
		case "twoCLGCSJ":
			break;
		case "twoXXXBSJ":
			break;
		case "twoSJCX":
			twosjcxDlgInit();
			break;
		case "threeSBGL":
			threesbglDlgInit();
			break;
		case "threeXXCJ":
			threexxcjDlgInit();
			break;
		case "threeDCWD":
			threedcwdDlgInit();
			break;
		case "threeBBSC":
			threebbscDlgInit();
			break;
		case "threeXXCX":
			threexxcxDlgInit();
			break;
		case "threeXXDR":
			threexxdrDlgInit();
			break;
		case "fourSBGL":
			break;
		case "fourCDSZ":
			break;
		case "fourZYJC":
			break;
		case "fourQCQF":
			break;
		case "fourCDWH":
			break;
		case "fiveCZFA":
			break;
		case "fiveCZZY":
			break;
		case "fiveCZGC":
			break;
		case "fiveCZBG":
			break;
		case "sixJCDC":
			break;
		case "sixJCDC":
			break;
		case "sixYJZS":
			break;
		case "sixYJYA":
			break;
		case "sixZDZH":
			break;
		case "sixYJDC":
		    break;
		case "sevYJHS":
			sevyjhsDlgInit();
			break;
	}
}